/**
 * 初始化提现申请详情对话框
 */
var WithdrawApplyInfoDlg = {
    withdrawApplyInfoData : {},
    validateFields: {
    	amount: {
            validators: {
                notEmpty: {
                    message: '金额不能为空'
                }
            }
        },
        pkAccountId: {
            validators: {
                notEmpty: {
                    message: '帐号不能为空'
                }
            }
        }
    }
       
};

/**
 * 清除数据
 */
WithdrawApplyInfoDlg.clearData = function() {
    this.withdrawApplyInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
WithdrawApplyInfoDlg.set = function(key, val) {
    this.withdrawApplyInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
WithdrawApplyInfoDlg.get = function(key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
WithdrawApplyInfoDlg.close = function() {
    parent.layer.close(window.parent.WithdrawApply.layerIndex);
}

/**
 * 收集数据
 */
WithdrawApplyInfoDlg.collectData = function() {
    this
    .set('amount')
    .set('pkAccountId');
}

WithdrawApplyInfoDlg.auditCollectData = function() {
    this
    .set('id')
    .set('status')
    .set('auditDesc');
}


/**
 * 验证数据是否为空
 */
WithdrawApplyInfoDlg.validate = function () {
    $('#withdrawApplayForm').data("bootstrapValidator").resetForm();
    $('#withdrawApplayForm').bootstrapValidator('validate');
    return $("#withdrawApplayForm").data('bootstrapValidator').isValid();
};


/**
 * 提交添加
 */
WithdrawApplyInfoDlg.addSubmit = function() {

	this.clearData();
	this.collectData();

    if (!this.validate()) {
        return;
    }

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/withdrawApply/add", function(data){
        Feng.success("添加成功!");
        window.parent.WithdrawApply.table.refresh();
        WithdrawApplyInfoDlg.close();
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.withdrawApplyInfoData);
    ajax.start();
}



/**
 * 提交添加
 */
WithdrawApplyInfoDlg.auditSubmit = function() {
	this.clearData();
	this.auditCollectData();
	var status = $("#status").val();
	if(status==null){
		alert("请选择审核结果");
	}
	
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/withdrawApply/audit", function(data){
        Feng.success("添加成功!");
        window.parent.WithdrawApply.table.refresh();
        WithdrawApplyInfoDlg.close();
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.withdrawApplyInfoData);
    ajax.start();
}

/**
 * 提交修改
 */
WithdrawApplyInfoDlg.editSubmit = function() {
	this.clearData();
	this.collectData();

    if (!this.validate()) {
        return;
    }

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/withdrawApply/update", function(data){
        Feng.success("修改成功!");
        window.parent.WithdrawApply.table.refresh();
        WithdrawApplyInfoDlg.close();
    },function(data){
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.withdrawApplyInfoData);
    ajax.start();
}

$(function() {
	 Feng.initValidator("withdrawApplayForm", WithdrawApplyInfoDlg.validateFields);

});
